/*
 * @Author: cys
 * @Date: 2018-11-15 12:56:55
 * @Last Modified by: cys
 * @Last Modified time: 2018-11-15 17:18:18
 * 全局路由钩子
 */

import VueRouter, { Route } from "vue-router";
import Vue, { VueConstructor } from "vue";

export const clearRouterCache = (vueRouter: VueRouter, Vue: VueConstructor) => {
  vueRouter.afterEach((to: Route, from: Route) => {
    const cacheRoutes = Vue.navigation.getRoutes();
    const length = cacheRoutes.length;
    // length > 4 &&
    if (!to.meta.touchBar) {
      Vue.navigation.cleanRoutes();
    }
  });
};

export const hooks = () => (router: VueRouter, Vue: VueConstructor) => {
  clearRouterCache(router, Vue);
  return router;
};
